$(function () {
    $("#jqGrid").Grid({
        url: '../sportspaymode/list',
        colModel: [
			{label: 'id', name: 'id', index: 'id', key: true, hidden: true},
			// {label: '用戶id', name: 'did', index: 'did', width: 80},
			{label: '支付方式', name: 'type', index: 'type', width: 80,align:'center',
				formatter:function(value){
					if(value==0){
						return "银行卡";
					}else if(value==1){
						return	"支付宝";
					}else if(value==2){
						return	"微信";
					}
				}
			},
			{label: '姓名', name: 'name', index: 'name', width: 80,align:'center'},
			{label: '开户行', name: 'bankName', index: 'bank_name', width: 80,align:'center'},
			{label: '开户行地址', name: 'bankAddress', index: 'bank_address', width: 80,align:'center'},
			{label: '银行卡号', name: 'cardNo', index: 'card_no', width: 80,align:'center'},
			{label: '手机号码', name: 'phone', index: 'phone', width: 80,align:'center'},
			{label: '支付宝或微信收款二维码', name: 'payUrl', index: 'pay_url', width: 80,align:'center'},
			{label: '账户(微信/支付宝)', name: 'account', index: 'account', width: 80,align:'center'},
			{label: '激活状态', name: 'isopen', index: 'isopen', width: 80,align:'center',
				formatter:function (value) {
					if(value==1){
						return "已激活";
					}else if(value==0){
						return "未激活";
					}
				}
			},
			{label: '添加时间', name: 'addTime', index: 'add_time', width: 80,align:'center',
				formatter:function(value){
					return transDate(value, 'yyyy-MM-dd hh:mm:ss');
				}
			}
			// {label: '修改时间', name: 'updateTime', index: 'update_time', width: 80}
			]
    });
});

let vm = new Vue({
	el: '#rrapp',
	data: {
        showList: true,
        title: null,
		sportsPaymode: {},
		ruleValidate: {
			name: [
				{required: true, message: '名称不能为空', trigger: 'blur'}
			]
		},
		q: {
		    name: '',
			paymode:''
		}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function () {
			vm.showList = false;
			vm.title = "新增";
			vm.sportsPaymode = {};
		},
		update: function (event) {
            let id = getSelectedRow("#jqGrid");
			if (id == null) {
				return;
			}
			vm.showList = false;
            vm.title = "修改";

            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
            let url = vm.sportsPaymode.id == null ? "../sportspaymode/save" : "../sportspaymode/update";
            Ajax.request({
			    url: url,
                params: JSON.stringify(vm.sportsPaymode),
                type: "POST",
			    contentType: "application/json",
                successCallback: function (r) {
                    alert('操作成功', function (index) {
                        vm.reload();
                    });
                }
			});
		},
		del: function (event) {
            let ids = getSelectedRows("#jqGrid");
			if (ids == null){
				return;
			}

			confirm('确定要删除选中的记录？', function () {
                Ajax.request({
				    url: "../sportspaymode/delete",
                    params: JSON.stringify(ids),
                    type: "POST",
				    contentType: "application/json",
                    successCallback: function () {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
					}
				});
			});
		},
		getInfo: function(id){
            Ajax.request({
                url: "../sportspaymode/info/"+id,
                async: true,
                successCallback: function (r) {
                    vm.sportsPaymode = r.sportsPaymode;
                }
            });
		},
		reload: function (event) {
			vm.showList = true;
            let page = $("#jqGrid").jqGrid('getGridParam', 'page');
			$("#jqGrid").jqGrid('setGridParam', {
                postData: {'name': vm.q.name,'paymode':vm.q.paymode},
                page: page
            }).trigger("reloadGrid");
            vm.handleReset('formValidate');
		},
        reloadSearch: function() {
            vm.q = {
                name: '',
				paymode:''
            }
            vm.reload();
        },
        handleSubmit: function (name) {
            handleSubmitValidate(this, name, function () {
                vm.saveOrUpdate()
            });
        },
        handleReset: function (name) {
            handleResetForm(this, name);
        },handleFormatError: function (file) {
			this.$Notice.warning({
				title: '文件格式不正确',
				desc: '文件 ' + file.name + ' 格式不正确，请上传 jpg 或 png 格式的图片。'
			});
		},handleMaxSize: function (file) {
			this.$Notice.warning({
				title: '超出文件大小限制',
				desc: '文件 ' + file.name + ' 太大，不能超过 2M。'
			});
		},handleSuccess: function (res, file) {//上传收款二维码图片
			vm.sportsPaymode.payUrl = file.response.url;
		},eyeImagePayUrl: function () {//预览收款二维码图片
			var url = vm.sportsPaymode.payUrl;
			eyeImage(url);
		}
	}
});